﻿CREATE TABLE [dbo].[CusomerInvoice] (
    [InvoiceId]    UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [CustomerId]   INT              NOT NULL,
    [Date]         DATE             NOT NULL,
    [Amount]       MONEY            NOT NULL,
    [State]        VARCHAR (20)     NOT NULL,
    [DateCreated]  DATETIME         DEFAULT (getdate()) NOT NULL,
    [CreatedBy]    VARCHAR (50)     DEFAULT (suser_sname()) NOT NULL,
    [DateModified] DATE             NULL,
    [ModifiedBy]   VARCHAR (50)     NULL,
    CONSTRAINT [PK_CusomerInvoice] PRIMARY KEY CLUSTERED ([InvoiceId] ASC),
    CONSTRAINT [FK_CusomerInvoice_Customer] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customer] ([CustomerId]) ON DELETE CASCADE ON UPDATE CASCADE
);


GO

CREATE INDEX [IX_CusomerInvoice_CustomerId] ON [dbo].[CusomerInvoice] ([CustomerId])
